<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>苏豫强的作业</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <script src="./city.js"></script>
</head>
<style>

</style>

<body>

    <select name="" id="prov">
        <option value="">请选择省</option>
    </select>
    <select name="" id="city">
        <option value="">请选择市</option>
    </select>
    <select name="" id="country">
        <option value="">请选择县/区</option>
    </select>



    <script>
        $(function () {
            var prov = $('#prov'),
                city = $('#city'),
                country = $('#country'),
                provindex = 0,
                cityindex = 0;
            (function showprov() {
                for (let i = 0; i < citys.length; i++) {
                    prov.append(`'<option value="${i}">${citys[i].name}</option>`)
                }
            })()
            prov.change(function () {
                provindex = $('#prov').find('option:selected').val();
                $('#city').html('<option>请选择市</option>')
                $('#country').html('<option>请选择县/区</option>')
                var cits = citys[provindex].city.length;
                for (let i = 0; i < cits; i++) {
                    city.append(`<option value="${i}">${citys[provindex].city[i].name}</option>`)
                }
            })
            city.change(function(){
                cityindex= $('#city').find('option:selected').val();
                $('#country').html('<option>请选择县/区</option>')
                var counts = citys[provindex]['city'][cityindex].area.length;
                for (let i = 0; i < counts; i++) {
                    country.append(`<option value="${i}">${citys[provindex]['city'][cityindex].area[i]}</option>`)
                }
            })
        })
    </script>







</body>

</html>